﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using System.Text;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using BCDto.OA.WorkSchedule.WorkSchedule;
using BCTMSRESTful.Configs;
using BCService.Utils;
using BCService.OA.WorkSchedule.WorkSchedule;
using BCCommon.OAEnums.WorkSchedule;

namespace BCTMSRESTful.Controllers.Management.OA.WorkSchedule
{
    /// <summary>
    /// 工作进度表
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class WorkScheduleController : ManagementBaseController
    {
        private readonly IWorkScheduleService workScheduleService;

        public WorkScheduleController(IWorkScheduleService workScheduleService)
        {
            this.workScheduleService = workScheduleService;
        }

        #region 添加工作进度表
        /// <summary>
        ///  添加工作进度表
        /// </summary>
        /// <param name="requestDto">工作进度表信息</param>
        /// <response code="201">添加工作进度表成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加工作进度表")]
        [ProducesResponseType(typeof(WorkScheduleDto), 201)]
        public IActionResult Post(
            [FromBody] WorkScheduleRequestDto requestDto)
        {
            var result = this.workScheduleService.Add(requestDto,this.Admin);
            return StatusCode((int)HttpStatusCode.Created, result);
        }
        #endregion

        #region 修改工作进度表
        /// <summary>
        ///  修改工作进度表
        /// </summary>
        /// <param name="workScheduleId">工作进度表Id</param>
        /// <param name="requestDto">工作进度表信息</param>
        /// <response code="200">修改工作进度表成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{work_schedule_id}")]
        [Log("修改工作进度表")]
        [ProducesResponseType(typeof(WorkScheduleDto), 200)]
        public IActionResult Put([FromRoute(Name = "work_schedule_id")] long workScheduleId, [FromBody] WorkScheduleRequestDto requestDto)
        {
            WorkSchedulePutDto putDto = requestDto.As<WorkSchedulePutDto>();
            putDto.WorkScheduleId = workScheduleId;
            return StatusCode((int)HttpStatusCode.OK, this.workScheduleService.Update(putDto,this.Admin));
        }
        #endregion

        #region 删除工作进度表
        /// <summary>
        ///  删除工作进度表
        /// </summary>
        /// <param name="workScheduleId">工作进度表Id</param>
        /// <response code="204">删除工作进度表成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpDelete("{work_schedule_id}")]
        [Log("删除工作进度表")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "work_schedule_id")] long workScheduleId)
        {
            this.workScheduleService.Delete(workScheduleId);
            return StatusCode((int)HttpStatusCode.NoContent);
        }
        #endregion

        #region 获取工作进度表
        /// <summary>
        ///  获取工作进度表
        /// </summary>
        /// <param name="workScheduleId">工作进度表Id</param>
        /// <response code="200">获取工作进度表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{work_schedule_id}")]
        [ProducesResponseType(typeof(WorkScheduleDto), 200)]
        public IActionResult Get([FromRoute(Name = "work_schedule_id")] long workScheduleId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.workScheduleService.Get(workScheduleId));
        }
        #endregion

        #region 获取工作进度表列表
        /// <summary>
        ///  获取工作进度表列表
        /// </summary>
		/// <param name="companyId">公司Id</param>
		/// <param name="departmentId">部门Id</param>
		/// <param name="scheduleType">工作进度表类型</param>
		/// <param name="start">开始时间</param>
		/// <param name="end">结束时间</param>
        /// <response code="200">获取工作进度表列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(WorkScheduleDto), 200)]
        public IActionResult List([FromQuery(Name = "company_id")] int? companyId,
            [FromQuery(Name = "department_id")] int? departmentId,
            [FromQuery(Name = "schedule_type")] OAWorkScheduleType scheduleType,
            [FromQuery(Name = "start")] DateTime start,
            [FromQuery(Name = "end")] DateTime end)
        {
            return StatusCode((int)HttpStatusCode.OK, this.workScheduleService.GetList(companyId,departmentId,scheduleType,start,end));
        }
        #endregion

        #region 获取工作进度表（分页）
        /// <summary>
        ///  获取工作进度表（分页）
        /// </summary>
		/// <param name="companyId">公司Id</param>
		/// <param name="departmentId">部门Id</param>
		/// <param name="scheduleType">工作进度表类型</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">当前页大小</param>
        /// <response code="200">获取工作进度表（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<WorkScheduleDto>), 200)]
        public IActionResult Query([FromQuery(Name = "company_id")] int? companyId,
            [FromQuery(Name = "department_id")] int? departmentId,
            [FromQuery(Name = "schedule_type")] OAWorkScheduleType scheduleType,
            [FromQuery(Name = "start")] DateTime? start,
            [FromQuery(Name = "end")] DateTime? end,
            [FromQuery(Name = "sort_name")] string sortName,
            [FromQuery(Name = "ascending")] bool? ascending,
            [FromQuery(Name = "page_index")] int pageIndex = 1,
            [FromQuery(Name = "page_size")] int pageSize = 10)
        {
            return StatusCode((int)HttpStatusCode.OK, this.workScheduleService.Query(companyId, departmentId, scheduleType, start, end, sortName, ascending, pageIndex, pageSize));
        }
        #endregion
    }
}

